const userRouter = require('koa-router')()
const userListMock = require('../mockdb/userList')

userRouter.post('/user/login', (ctx:any ) => {
  const { username } = ctx.request.body

  for (const user of userListMock) {
    if (username === user.username) {
      return ctx.body = {
        code: 200,
        message: '登录成功',
        data: {
          ...user,
          accessToken: username + '-token'
        }
      }
    }
  }

  ctx.body = {
    code: 401,
    message: '用户未找到',
    data: {}
  }
})

module.exports = userRouter